<html>
<head><meta charset="utf-8"><title>bad note for non-object-safe method in another module · t-compiler/wg-diagnostics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/index.html">t-compiler/wg-diagnostics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html">bad note for non-object-safe method in another module</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="167319134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319134">(Jun 04 2019 at 17:50)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">pub</span><span class="w"> </span><span class="k">trait</span><span class="w"> </span><span class="n">Example</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">query</span><span class="o">&lt;</span><span class="n">Q</span><span class="o">&gt;</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">q</span>: <span class="nc">Q</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">impl</span><span class="w"> </span><span class="n">Example</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="kt">i32</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">query</span><span class="o">&lt;</span><span class="n">Q</span><span class="o">&gt;</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span><span class="w"> </span><span class="n">_</span>: <span class="nc">Q</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">unimplemented</span><span class="o">!</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">nested</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">use</span><span class="w"> </span><span class="k">super</span>::<span class="n">Example</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">example</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="mf">1.</span><span class="n">query</span>::<span class="o">&lt;</span><span class="nb">ToString</span><span class="o">&gt;</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</pre></div>


<div class="codehilite"><pre><span></span>error: the `query` method cannot be invoked on a trait object
  --&gt; src/lib.rs:14:11
   |
14 |         1.query::&lt;ToString&gt;(&quot;&quot;)
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`
</pre></div>


<p>The error message is good, but the <code>note</code> is not — that's the trait we are already using.</p>



<a name="167319179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319179">(Jun 04 2019 at 17:51)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span> should I file this?</p>



<a name="167319301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319301">(Jun 04 2019 at 17:52)</a>:</h4>
<p>Actually, <em>is</em> the error correct? <code>1</code> isn't a trait object.</p>



<a name="167319662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319662">(Jun 04 2019 at 17:56)</a>:</h4>
<p>I think that the _error_ might be correct, in that <code>rustc</code> correctly complains, but the exposed message is incorrect</p>



<a name="167319675"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319675" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319675">(Jun 04 2019 at 17:56)</a>:</h4>
<p>go ahead and file</p>



<a name="167319698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319698">(Jun 04 2019 at 17:56)</a>:</h4>
<p>we either have to make this compile _or_ handle the case in the emitted diagnostic</p>



<a name="167319844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319844">(Jun 04 2019 at 17:58)</a>:</h4>
<p><span class="user-mention" data-user-id="116155">@Jake Goulding</span> just realized the problem. It's not that <code>i32</code> is a trait object, is that <code>ToString</code> is.<br>
<a href="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=091474ba4cbe4a91a5f731427e31dbc4" target="_blank" title="https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=091474ba4cbe4a91a5f731427e31dbc4">https://play.rust-lang.org/?version=nightly&amp;mode=debug&amp;edition=2018&amp;gist=091474ba4cbe4a91a5f731427e31dbc4</a></p>



<a name="167319906"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167319906" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167319906">(Jun 04 2019 at 17:59)</a>:</h4>
<p>So yes, the error is "correct", but we need to differentiate the problem originating from <code>self</code> and from type arguments</p>



<a name="167321002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167321002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167321002">(Jun 04 2019 at 18:10)</a>:</h4>
<p><span class="user-mention" data-user-id="119031">@Esteban Küber</span>  Should I file as two things? One for the note and one for distinguishing?</p>



<a name="167323489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167323489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167323489">(Jun 04 2019 at 18:32)</a>:</h4>
<p>Na, just one ticket should be fine</p>



<a name="167324870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/bad%20note%20for%20non-object-safe%20method%20in%20another%20module/near/167324870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/bad.20note.20for.20non-object-safe.20method.20in.20another.20module.html#167324870">(Jun 04 2019 at 18:47)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/61525" target="_blank" title="https://github.com/rust-lang/rust/issues/61525">https://github.com/rust-lang/rust/issues/61525</a></p>
<p>Thanks!</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>